package com.peanut.baby.mvp.reg;

/**
 * Created by anonymouslystudio on 2017/7/5.
 */

public class RegistPresenter implements RegistContract.Presenter{


    private RegistContract.View mView;

    public RegistPresenter(RegistContract.View view){
        this.mView = view;
    }

    @Override
    public void getVcode(String mobile) {
        //TODO
        startCountDown();
    }

    @Override
    public void submitRegistForm(String mobile, String vcode, String password) {

    }

    private void startCountDown(){
        new Thread(new CountingRunnable()).start();
    }

    /**
     * 计数器
     */
    class CountingRunnable implements Runnable{
        int current = 60;
        public CountingRunnable() {
        }

        @Override
        public void run() {
            mView.startCountDown();
            while(current > 0){
                mView.onCountDown(current);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
                current --;
            }
            mView.onCountComplete();

        }
    }
}
